package com;

import java.awt.AWTException;
import java.awt.Frame;
import java.awt.Image;
import java.awt.SystemTray;
import java.awt.Toolkit;
import java.awt.TrayIcon;
import java.awt.Window;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.io.IOException;

import javax.swing.JFrame;



public class TrayAll extends Thread implements ActionListener{
	private Window miFrame;
	private MainControler WifiRemoteControler;

	public TrayAll(Window miFrame2, MainControler mc) {
		// TODO Auto-generated constructor stub
		miFrame=miFrame2;
		WifiRemoteControler=mc;
	}


	public void run() {
		if(java.awt.SystemTray.isSupported()){
    	    final java.awt.SystemTray sTray =  java.awt.SystemTray.getSystemTray();
    	    //Creo el icono
    	    java.awt.Image img = java.awt.Toolkit.getDefaultToolkit().getImage("tray.png");

    	    //Añado menu
    	    java.awt.PopupMenu pMenu = new java.awt.PopupMenu();
    	    final java.awt.TrayIcon tIcon  = new java.awt.TrayIcon(img, "WifiRemote", pMenu);

    	    //Anado entradas al menu
    	    java.awt.MenuItem Restore = new java.awt.MenuItem("Restaurar");
    	    Restore.addActionListener(this);
    	    pMenu.add(Restore);
    	    java.awt.MenuItem close = new java.awt.MenuItem("Cerrar");
    	    close.addActionListener(this);
    	    pMenu.add(close);
    	    try{
    	    	sTray.add(tIcon);
    	    }catch(Exception e){
    	    	System.out.println("Hubo un problema: \n"+e.getMessage() +"\n");
    	    }
		}
	}


	@Override
	public void actionPerformed(ActionEvent arg0) {
		// TODO Auto-generated method stub
		if(arg0.getActionCommand().equals("Restaurar")){
			miFrame.setVisible(true);
		}
		if(arg0.getActionCommand().equals("Cerrar")){
			System.exit(0);
		}

	}


}